package com.example.controller;

import com.example.entity.Clients;
import com.example.entity.User;
import com.example.dao.UserMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.collections.map.HashedMap;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/user")

public class UserController {

    @Autowired
    private UserMapper userMapper;

    @RequiresPermissions("super")
    @GetMapping(value = "getUserAll",produces = "text/html;charset=UTF-8")
    public String getClientAll() throws Exception{
        List<User> cList = userMapper.selectAll();
        ObjectMapper mapper = new ObjectMapper();
        String JSONString =  mapper.writeValueAsString(cList);
        return JSONString;
    }

    @RequiresPermissions("super")
    @RequestMapping(value = "edit",produces = "text/html;charset=UTF-8")
    public String edit(@RequestBody User user) throws Exception{
        int result = userMapper.updateByPrimaryKeySelective(user);
        ObjectMapper mapper = new ObjectMapper();
        String JSONString =  mapper.writeValueAsString(result);
        return JSONString;
    }
}